﻿using System;
using System.Data.OleDb;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Linq;
using System.Web;

namespace QLSTK_DAL_WS
{
    public class DataProvider
    {
        private static string _connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\0941014_0941150\QLSTK_DAL_WS\QLSTK_DAL_WS\QLSTK_DAL_WS\App_Data\Database_STK.mdb";

        public static string ConnectionString
        {
            get { return DataProvider._connectionString; }
            set { DataProvider._connectionString = value; }
        }

        protected OleDbConnection connection;
        protected OleDbDataAdapter adapter;
        protected OleDbCommand command;

        public void connect()
        {
            connection = new OleDbConnection(ConnectionString);
            connection.Open();
        }

        public void disconnect()
        {
            connection.Close();
        }

        public IDataReader ExcuteQuery(string sqlString)
        {
            command = new OleDbCommand(sqlString, connection);
            return command.ExecuteReader();
        }

        public void ExcuteNonQuery(string sqlString)
        {
            command = new OleDbCommand(sqlString, connection);
            command.ExecuteNonQuery();
        }

        public object ExcuteScalar(string sqlString)
        {
            command = new OleDbCommand(sqlString, connection);
            return command.ExecuteScalar();
        }

        protected virtual object GetDataFromDataRow(DataTable dt, int i)
        {
            return null;
        }

        protected ArrayList ConvertDataSetToArrayList(DataSet dataset)
        {
            ArrayList arr = new ArrayList();
            DataTable dt = dataset.Tables[0];
            int i, n = dt.Rows.Count;
            for (i = 0; i < n; i++)
            {
                object obj = GetDataFromDataRow(dt, i);
                arr.Add(obj);
            }
            return arr;
        }
    }
}